<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增施工日志')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-recording-add"  th:object="${pId}">
            <div class="form-group">    
                <label class="col-sm-3 control-label">资料名称：</label>
                <div class="col-sm-8">
                    <input id="cName" name="cName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上传资料：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="pData" class="form-control" type="file" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">上传时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input id="cTime" name="cTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="cRemark" name="cRemark" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">材料名称：</label>
                <div class="col-sm-8">
                    <select class="form-control noselect2 selectpicker" id="cTname"></select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">材料数量：</label>
                <div class="col-sm-8">
                    <input id="cTnum" name="cTnum" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group" hidden>
                <label class="col-sm-3 control-label">外键id：</label>
                <div class="col-sm-8">
                    <input id="cPid" name="cPid" class="form-control" type="text" th:value="${pId}">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var idss=[[*{pId}]];
        var prefix = ctx + "ruoyi/recording"
        var prefixs = ctx + "ruoyi/stock"
        $("#form-recording-add").validate({
            focusCleanup: true
        });
        uplike();
        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }
        function uplike(){
            $.ajax({
                url: prefixs + "/like/"+idss,
                type: "post",
                dataType:"json",
                data: {},
                success: function(data){
                    if(data.length>0){
                        for(i in data){
                            $("#cTname").append("<option>"+data[i].tName+"</option>")
                        }
                    }else{
                        $("#cTname").append("<option>暂无数据</option>")
                    }
                }
            });
        }

        function uploadFile() {
            var formData = new FormData();
            if ($('#filePath')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                return false;
            }
            formData.append('cName', $("#cName").val());
            formData.append('cTime', $("#cTime").val());
            formData.append('cRemark', $("#cRemark").val());
            formData.append('cTname', $("#cTname").val());
            formData.append('cTnum', $("#cTnum").val());
            formData.append('cPid', $("#cPid").val());
            formData.append('file', $('#filePath')[0].files[0]);
            $.ajax({
                url: prefix + "/add/",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }

        $("input[name='cTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    </script>
</body>
</html>